package com.usian.article.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.usian.common.dtos.ResponseResult;
import com.usian.model.article.dtos.ArticleDto;
import com.usian.model.article.dtos.ArticleHomeDto;
import com.usian.model.article.dtos.ArticleInfoDto;
import com.usian.model.media.dtos.WmNewsResultDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.usian.article.service.IApArticleService;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 文章信息表，存储已发布的文章 前端控制器
 * </p>
 *
 * @author usian
 * @since 2022-07-12
 */
@RestController
@RequestMapping("/api/v1/article")
@Api(tags = "文章信息表，存储已发布的文章接口")
@CrossOrigin
public class ApArticleController{

    @Autowired
    private IApArticleService apArticleService;

    /**
     * 保存 app文章信息
     * @param wmNewsDTO
     * @return
     */
    @PostMapping("/save")
    public Long saveArticle(@RequestBody WmNewsResultDTO wmNewsDTO) {
        return apArticleService.saveArticle(wmNewsDTO);
    }

    /**
     * 加载首页文章
     * @return
     */
    @PostMapping("/load")
    public ResponseResult<List<ArticleDto>> load(@RequestBody ArticleHomeDto dto) {
        List<ArticleDto> articleDtoList = apArticleService.load(dto,1);
        return ResponseResult.ok(articleDtoList);
    }
    /**
     * 加载更多
     * @return
     */
    @PostMapping("/loadmore")
    public ResponseResult<List<ArticleDto>> loadMore(@RequestBody ArticleHomeDto dto) {
        List<ArticleDto> articleDtoList =  apArticleService.load(dto,1);
        return ResponseResult.ok(articleDtoList);
    }
    /**
     * 加载最新
     * @return
     */
    @PostMapping("/loadnew")
    public ResponseResult<List<ArticleDto>> loadNew(@RequestBody ArticleHomeDto dto) {
        List<ArticleDto> articleDtoList =   apArticleService.load(dto,2);
        return ResponseResult.ok(articleDtoList);
    }
    /**
     * 加载文章详情
     */
    @PostMapping("/load_article_info")
    public ResponseResult<Map<String,Object>> loadArticleInfo(@RequestBody ArticleInfoDto dto){
        Map<String,Object> map = apArticleService.loadArticleInfo(dto);
        return ResponseResult.ok(map);
    }

    /**
     * 回显
     * @param dto
     * @return
     */
    @PostMapping("/load_article_behavior")
    public ResponseResult loadArticleBehavior(@RequestBody ArticleInfoDto dto){
        Map<String, Boolean> map = apArticleService.loadArticleBehavior(dto);
        return ResponseResult.ok(map);
    }

    /**
     * 分页查询文章信息
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/findByPage")
    public List<ArticleDto> findArticleByPage(@RequestParam(name = "page") int page, @RequestParam(name = "size") int size){
        return apArticleService.findArticleByPage(page,size);
    }
}
